#include "GameEngine/GameEngine.h"

colorRGBA	*GameEngine::backgroundColor=&defaultBackgroundColor;
Camera		*GameEngine::currentCamera=new Camera();
SkyBox		*GameEngine::currentSkyBox;

GameEngine::GameEngine(NativeDisplayType hDC,NativeWindowType m_hWnd){
	InitOGLES(hDC,m_hWnd);
#ifndef __APPLE__
	m_Extensions.LoadExtensions();
#else
	m_Extensions.glCurrentPaletteMatrixOES			= ::glCurrentPaletteMatrixOES;
	m_Extensions.glLoadPaletteFromModelViewMatrixOES	= ::glLoadPaletteFromModelViewMatrixOES;
	m_Extensions.glMatrixIndexPointerOES				= ::glMatrixIndexPointerOES;
	m_Extensions.glWeightPointerOES					= ::glWeightPointerOES;
#endif
	::glViewport(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);		// Reset The Current Viewport
	::glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	::glLoadIdentity();									// Reset The Projection Matrix
	::glMatrixMode(GL_MODELVIEW);						// Select The Modelview Matrix
	::glLoadIdentity();									// Reset The Modelview Matrix

	::glClearColor(backgroundColor->R, backgroundColor->G, backgroundColor->B, backgroundColor->A);
	::glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	::glEnable(GL_ALPHA_TEST);
	::glAlphaFunc(GL_GREATER, 0.1f);
	::glDepthFunc(GL_LEQUAL);
	::glDepthMask(GL_TRUE);
	//glDepthRangef(.1, .5);
	//::glShadeModel(GL_SMOOTH);

	::glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
	//::glEnable(GL_LINE_SMOOTH);
	//::glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
	//::glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
	
	float tmp=defaultFarClip/(sqrt(3.0f));
	currentSkyBox=new SkyBox(tmp,true,512);

	flushOGLES();
}

Camera* GameEngine::getCamera(){
	return GameEngine::currentCamera;
}
